package com.ruoyi.web.controller.blog.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.blog.service.IWebTagService;
import com.ruoyi.model.tag.WebTag;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标签Controller
 *
 * @author ruoyi
 * @date 2024-04-16
 */
@Api(tags = "后台:标签接口")
@RestController
@RequestMapping("/admin/tag")
public class WebTagController extends BaseController {
    @Autowired
    private IWebTagService webTagService;

    /**
     * 查询标签列表
     */
    @PreAuthorize("@ss.hasPermi('system:tag:list')")
    @GetMapping("/list")
    public TableDataInfo list(WebTag webTag) {
        startPage();
        List<WebTag> list = webTagService.selectWebTagList(webTag);
        return getDataTable(list);
    }

    /**
     * 导出标签列表
     */
    @PreAuthorize("@ss.hasPermi('system:tag:export')")
    @Log(title = "导出标签列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WebTag webTag) {
        List<WebTag> list = webTagService.selectWebTagList(webTag);
        ExcelUtil<WebTag> util = new ExcelUtil<WebTag>(WebTag.class);
        util.exportExcel(response, list, "标签数据");
    }

    /**
     * 获取标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(webTagService.selectWebTagById(id));
    }

    /**
     * 新增标签
     */
    @PreAuthorize("@ss.hasPermi('system:tag:add')")
    @Log(title = "新增标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WebTag webTag) {
        return toAjax(webTagService.save(webTag));
    }

    /**
     * 修改标签
     */
    @PreAuthorize("@ss.hasPermi('system:tag:edit')")
    @Log(title = "修改标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WebTag webTag) {
        return toAjax(webTagService.updateWebTag(webTag));
    }

    /**
     * 删除标签
     */
    @PreAuthorize("@ss.hasPermi('system:tag:remove')")
    @Log(title = "标签标签", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(webTagService.deleteWebTagByIds(ids));
    }
}
